﻿#include "SkillMoveAOE.h"
#include "Character/SkillPart.h"
#include "base/core/log.h"
#include "base/core/com_define.h"
#include "base/core/utility.h"
#include "Scene/MapMgr.h"
#include "Character/CreatureMgr.h"
#include "Character/monster/Monster.h"


SkillMoveAOE::SkillMoveAOE()
{
}

SkillMoveAOE::~SkillMoveAOE()
{
}

void SkillMoveAOE::OnDamageTimedo(uint32_t skillId)
{
	CharIDType targetCid = 0;
	uint32_t nTime = 0;
	float distance = 0;
	Point3<float> tmpPos;
	cList::iterator iter;
	cList  targetCidList;
	const SkillCfg* pConfig = g_GetSkillMgr()->GetSkillCfg(skillId);
	MMOLOG_PROCESS_ERROR(pConfig);

	m_pPart->KillTimedo(m_nGlobelID);

	//LogDebugFmtPrint("skill damagetimeDo, curdamgeCount:%d, skillId:%d, targetCid:%d", pSkill->curDamageCount, skillId, targetCid);

	//坐标前移
	for (int i = 0; i <= (int)m_curDamageCount; ++i)
	{
		nTime += pConfig->damageTime[i];
	}

	//距离等于速度乘时间
	distance = nTime / 1000.0f*pConfig->bulledSpeed / 1000.0f;

	tmpPos = m_pPart->GetMasterPos() + m_skillDir*distance;

	m_pPart->FindCreatures(pConfig, tmpPos, m_skillDir, targetCid, tmpPos, m_curDamageCount, m_focoTime, targetCidList);
	iter = std::find(targetCidList.begin(), targetCidList.end(), m_pPart->GetMasterCid());
	if (iter!=targetCidList.end())
	{
		targetCidList.erase(iter);
	}
	//计算技能结果
	m_pPart->SkillResult(skillId, pConfig, m_curDamageCount, m_focoTime, targetCidList);

	if ((uint32_t)pConfig->damageTime.size() > m_curDamageCount + 1)
	{
		m_curDamageCount++;
		m_pPart->SetTimedo(m_nGlobelID, pConfig->damageTime[m_curDamageCount], 1);
	}
	else
	{
		//LogDebugFmtPrint("skill damge done, skillId:%d", skillId);
		//refreshData();

		if (m_vSkillId.size() > 1)
		{
			OnNextSkillState(skillId);
		}
		else
		{
			//技能一次释放完成，需要删通知删除
			m_pPart->RemoveSkillFightInfo(m_nGlobelID);
		}
	}
	return;
Exit0:
	m_pPart->KillTimedo(m_nGlobelID);
	m_pPart->RemoveSkillFightInfo(m_nGlobelID);
}